(function($) {
	var imgList = [];
	$.extend({
		preload: function(imgArr, option) {
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push($("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);


$(function() {
	$.preload([
		"public/imageskht/about_bg.png",
		"public/imageskht/aerow_type1.png",
		"public/imageskht/aerow_type2.png",
		"public/imageskht/client_detail_bg.png",
		"public/imageskht/cloud.png",
		"public/imageskht/contact_ater_mark.png",
		"public/imageskht/contact_bg.png",
		"public/imageskht/home_globe.png",
		"public/imageskht/include_img.png",
		"public/imageskht/input_bg.png",
		"public/imageskht/khotoot_logo.png",
		"public/imageskht/khotoot_title.png",
		"public/imageskht/logo.png",
		"public/imageskht/lt_shadow.png",
		"public/imageskht/main_menu.png",
		"public/imageskht/menu.png",
		"public/imageskht/profile_bg.png",
		"public/imageskht/services_bg.png",		
		"public/imageskht/signal_art.png",
		"public/imageskht/social_nav.png",
		"public/imageskht/work_img_1.png",
		"public/imageskht/work_img_2.png",
		"public/imageskht/text_area_bg.png"		
		], {
		init: function(loaded, total) {
			$("#wrapper").hide();
			$("#loadingtext").html("Khotoot Is A Digital Graphic Design Company");
		},
		loaded: function(img, loaded, total) {
			var loader = 245-((loaded/total)*245);
			var prozent = Math.round(loaded/total*100);
			$("#loadingtext").html("Loading: "+prozent+"%");
			$("#loadingbar").css({"background-position" : "0px "+loader+"px"});
		},
		loaded_all: function(loaded, total) {
			$("#loadingtext").html("Khotoot Is A Digital Graphic Design Company");
			$("#preloader").delay(500).fadeOut();
			$("#wrapper").delay(1000).fadeIn("slow");
		}
	});

});
